package com.tdmh.test.algorithm;

/**
 * @author leimingchao
 * @create 2021-03-29 13:30
 */
public class Solution {
    public static void main(String[] args) {
        reverseBits(32);
    }

    public static int reverseBits(int n) {
        String binaryString = Integer.toBinaryString(n);
        System.out.println("转换之前:"+binaryString);
        char[] charArray = binaryString.toCharArray();
        for (int i = 0; i < charArray.length ; i++) {
            char c = charArray[i];
            if (c=='0'){
                charArray[i]='1';
            }else{
                charArray[i]='0';
            }
        }
        String newString=new String(charArray);
        System.out.println("转换之后:"+newString);
        return Integer.parseInt(newString,2);
    }
}
